package com.hmsm.sys.po;

import java.util.ArrayList;
import java.util.List;

/**
 * FuncInfo entity. @author MyEclipse Persistence Tools
 */

@SuppressWarnings("serial")
public class FuncInfo implements java.io.Serializable {

	// Fields

	private Integer pkId;
	private String name;
	private String funcCode;
	private Integer parentId;
	private FuncInfo parent;
	private List<FuncInfo> subFuncs;

	// Constructors

	public FuncInfo getParent() {
		return parent;
	}

	public void setParent(FuncInfo parent) {
		this.parent = parent;
	}

	public List<FuncInfo> getSubFuncs() {
		return subFuncs;
	}

	public void setSubFuncs(List<FuncInfo> subFuncs) {
		this.subFuncs = subFuncs;
	}

	/** default constructor */
	public FuncInfo() {
	}

	/** full constructor */
	public FuncInfo(Integer pkId, String name, String funcCode, Integer parentId) {
		this.pkId = pkId;
		this.name = name;
		this.funcCode = funcCode;
		this.parentId = parentId;
	}

	// Property accessors

	public Integer getPkId() {
		return this.pkId;
	}

	public void setPkId(Integer pkId) {
		this.pkId = pkId;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getFuncCode() {
		return this.funcCode;
	}

	public void setFuncCode(String funcCode) {
		this.funcCode = funcCode;
	}

	public Integer getParentId() {
		return this.parentId;
	}

	public void setParentId(Integer parentId) {
		this.parentId = parentId;
	}

	public String getPath() {
		String path;
		
		String groupName = "";
		String funcName = "";
		String rangeName = "";
		path = groupName+":"+funcName;
		
		if(isFuncGroup()){
			path = name;
		}else if(isFuncInfo()){
			path = parent.getName()+":"+name;
		}else{
			path = getParentList().get(0).getName()+":"+getParentList().get(1).getName()+"("+name+")";
		}
		
		return path;
	}
	
	public List<FuncInfo> getParentList() {
		List<FuncInfo> parentList = new ArrayList<FuncInfo>();
		
		if(parent!=null){
			for(FuncInfo p:parent.getParentList()){
				parentList.add(p);
			}
			parentList.add(parent);
		}
		
		return parentList;
	}

	public boolean isFuncGroup() {
		boolean result = false;
		
		result = this.getParent()==null;
		
		return result;
	}
	
	public boolean isFuncInfo() {
		boolean result = false;
		
		if(this.getParent()!=null){
			result = this.getParent().getParent()==null;
		}
		
		return result;
	}

}

enum FuncType {
	/**
	 * 权限分组
	 */
	GROUP, 
	
	/**
	 * 功能权限
	 */
	FUNC, 
	
	/**
	 * 权限范围
	 */
	RANGE, 
	
	/**
	 * 二维权限范围列
	 */
	RANGE_X, 
	
	/**
	 * 二维权限范围行
	 */
	RANGE_Y, 
	
	/**
	 * 权限范围项
	 */
	RANGE_ITEM
}
